#include "threadPool.h"
#include <stdio.h>

int threadPooInit(pThreadPool_t pthreadPool, int threadNum){
    bzero(pthreadPool,sizeof(threadPool_t));
    pthreadPool->pthid = (pthread_t *)calloc(threadNum,sizeof(pthread_t));
    pthreadPool->threadNum = threadNum;
    taskQueueInit(&pthreadPool->taskQueue);
    printf("pthread num=%d\n",pthreadPool->threadNum);
    return 0;
}
int startThreadPool(pThreadPool_t pthreadPool){

    for(int i = 0; i < pthreadPool->threadNum; ++i){
        pthread_create(pthreadPool->pthid+i,NULL,child_handle,&pthreadPool->taskQueue);
    }
    return 0;
}
int closeThreadPool(pThreadPool_t pthreadPool){
    for(int i = 0; i < pthreadPool->threadNum; ++i){
        pthread_join(pthreadPool->pthid[i],NULL);
    }

    return 0;
}
